import time
import Page
from Page import Launcher
from Base.Base import Base
from selenium.webdriver.common.by import By


class LauncherIndexPage(Base):
    """
    桌面首页页面

    """

    def __init__(self, driver):
        Base.__init__(self, driver)

        # 首页列表按钮
        self.index_app_list_btn = (By.XPATH, Launcher.RESOURCE_ID.format("iv_go_app_list"))

        # 首页音乐标题
        self.index_music_name_text = (By.XPATH, Launcher.RESOURCE_ID.format("tv_music_name"))

        # 首页音乐歌手
        self.index_singer_name_text = (By.XPATH, Launcher.RESOURCE_ID.format("tv_music_singer"))

        # 首页用户头像
        self.index_person_icon_img = (By.XPATH, Launcher.RESOURCE_ID.format("tv_music_singer"))

        # 首页用户名称
        self.index_person_name_text = (By.XPATH, Launcher.RESOURCE_ID.format("tv_name"))

        # 桌面音乐封面(暂不封装)
        self.index_music_cover_img = (By.XPATH, Launcher.RESOURCE_ID.format("viewpager"))

        # 桌面地图
        self.index_map_img = (By.XPATH, Launcher.RESOURCE_ID.format("iv_map_init"))

        # 桌面服务
        self.index_service_img = (By.XPATH, Launcher.RESOURCE_ID.format("iv_service_init"))

        # 桌面收藏按钮
        self.index_collection_btn = (By.XPATH, Launcher.RESOURCE_ID.format("iv_favourite"))

        # 桌面上一曲按钮
        self.index_prev_btn = (By.XPATH, Launcher.RESOURCE_ID.format("iv_previous"))

        # 桌面播放按钮
        self.index_play_btn = (By.XPATH, Launcher.RESOURCE_ID.format("iv_play"))

        # 桌面下一曲按钮
        self.index_next_btn = (By.XPATH, Launcher.RESOURCE_ID.format("iv_next"))

        # 桌面歌词按钮
        self.index_lyric_btn = (By.XPATH, Launcher.RESOURCE_ID.format("iv_lyric"))

        # 桌面听歌识曲按钮
        self.index_ting_btn = (By.XPATH, Launcher.RESOURCE_ID.format("iv_lyric"))

        # 桌面地图搜索按钮
        self.index_map_search_btn = (By.XPATH, Launcher.RESOURCE_ID.format("iv_search_map"))

        # 桌面地图首页按钮
        self.index_map_home_btn = (By.XPATH, Launcher.RESOURCE_ID.format("iv_go_home"))

        # 桌面服务搜索按钮
        self.index_service_search = (By.XPATH, Launcher.RESOURCE_ID.format("iv_search_service"))

    def get_cover_img(self):
        """
        获取

        :return:
        """
        return self.find_element_o(self.index_music_cover_img)

    def click_app_list(self):
        """
        点击应用列表

        :return: None
        """
        self.click_element(self.index_app_list_btn)

    # 元素带有NAF属性, 无法使用
    # def get_Page_collection(self):
    #     """
    #     获取桌面的收藏按钮
    #
    #     :return:
    #     """
    #     self.find_element_o(Page.Page_index_collection_btn)

    def click_collection(self):
        """
        点击收藏按钮

        :return:
        """
        self.click_element(self.index_collection_btn)

    def click_play(self):
        """
        点击播放按钮

        :return:
        """
        self.click_element(self.index_play_btn)

    def is_display_app_list_btn(self):
        """
        是否展示应用列表按钮
        :return:
        """
        return self.is_display(self.index_app_list_btn)

    def swipe_cover(self):
        """
        滑动桌面的封面

        :return:
        """

        self.swipe_o(location=(460, 600, 260, 500), direction="up")
